home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 …ember: Reference Library / Apple Developer Reference Library (December 1999) (Disk 1).iso / pc / technical documentation / develop / develop issue 27 / develop issue 27 code / 3d game controls / source / gamecontrols.h < prev    next >
Encoding:
Text File  |  1996-06-29  |  4.8 KB  |  148 lines

  1. //--------------------------------------------------------------------------------------------
  2. //  Game Controller Declarations
  3. //
  4. //      by Philip McBride
  5. //
  6. //--------------------------------------------------------------------------------------------
  7.  
  8. //--------------------------------------------------------------------------------------------
  9. //  Includes
  10. //
  11.  
  12. #include <QDOffscreen.h>
  13.  
  14. #include <QD3D.h>
  15. #include <QD3DAcceleration.h>
  16. #include <QD3DCamera.h>
  17. #include <QD3DController.h>
  18. #include <QD3DDrawContext.h>
  19. #include <QD3DErrors.h>
  20. #include <QD3DGeometry.h>
  21. #include <QD3DGroup.h>
  22. #include <QD3DIO.h>
  23. #include <QD3DLight.h>
  24. #include <QD3DMath.h>
  25. #include <QD3DPick.h>
  26. #include <QD3DRenderer.h>
  27. #include <QD3DSet.h>
  28. #include <QD3DShader.h>
  29. #include <QD3DStorage.h>
  30. #include <QD3DString.h>
  31. #include <QD3DStyle.h>
  32. #include <QD3DTransform.h>
  33. #include <QD3DView.h>
  34.  
  35.  
  36. //--------------------------------------------------------------------------------------------
  37. //  Defines and Constants
  38. //
  39.  
  40. #define        kGestaltTrap            0xA0AD
  41.  
  42. // some 3D constants
  43. static const TQ3ColorARGB    kMyAClearColor            = {1.0,1.0,1.0, 1.0};
  44. static const Rect            kMyBoundsRect            = {42,4,282,324};
  45.  
  46. static const TQ3Point3D        kMyDefaultFrom            = {0.0,0.0,1.0};
  47. static const TQ3Point3D        kMyDefaultTo            = {0.0,0.0,0.0};
  48. static const TQ3Vector3D    kMyDefaultUp            = {0.0,1.0,0.0};
  49. static const float            kMyDefaultHither        = 0.01;
  50. static const float            kMyDefaultYon            = 1000000.0;
  51.  
  52. // Here are our hard coded movement factors.  We tried to make these general
  53. // for any size model, but in the end they are really tuned for simple models.
  54. // Especially the rotation factors.  What seems to help is to remove or at
  55. // least minimize the model dimension (maxDimension used in MyInitDeltaFactors)
  56. // used to multiply the ...RotFactor structure fields of the document.  Some
  57. // experimentation is needed here.
  58. static const float            kXRotFactorBase            = 0.005;
  59. static const float            kYRotFactorBase            = 0.05;
  60. static const float            kZRotFactorBase            = 0.001;
  61. static const float            kXMoveFactorBase        = 0.01;
  62. static const float            kYMoveFactorBase        = 0.005;
  63. static const float            kZMoveFactorBase        = 0.01;
  64. static const float            kControlFactorBase        = 0.01;
  65.  
  66.  
  67. // Here are some hard coded keys -- yikes.  Of course this is just to keep
  68. // things simple.  You will want to replace this with a nice preference setup.
  69. // Further, when QuickDraw 3D has keyboard (and mouse) controllers, this should
  70. // all go through that mechanism.  Note, use the char codes to the right instead
  71. // of the numbers if you are using the alternative MyDoKeyMove function in
  72. // GameControls.c that switches off the char theKey argument.
  73.  
  74. enum {
  75.     iRight =    7,        //'x',
  76.     iLeft =        6,        //'z',
  77.     iUp =        3,        //'f',
  78.     iDown =        9,        //'v',
  79.     iForward =    91,        //'8',
  80.     iBackward =    87,        //'5',
  81.     iPanRight =    88,        //'6',
  82.     iPanLeft =    86,        //'4',
  83.     iPanUp =    2,        //'d',
  84.     iPanDown =    8,        //'c',
  85.     iBankL =    89,        //'7',
  86.     iBankR =    92,        //'9',
  87.     iLeftArrow = 123,    //'\34',
  88.     iRightArrow = 124,    //'\35',
  89.     iDownArrow = 125,    //'\37',
  90.     iUpArrow = 126        //'\36'
  91. } ;
  92.  
  93.  
  94. //--------------------------------------------------------------------------------------------
  95. //  Document Structure
  96. //
  97.  
  98. // our document structure (we use one for each window (and thus model))
  99. typedef struct _DocumentRecord {
  100.     CWindowPtr        theWindow;                        // display window
  101.     FSSpec            theFileSpec;                    // input file & ref
  102.     short            fRefNum;
  103.     TQ3GroupObject    documentGroup;                    // main group for the document
  104.     TQ3ViewObject    theView;                        // the documents view object
  105.     TQ3Object        viewHints;                        // viewhints of the model
  106.     
  107.     TQ3ShaderObject            illuminationShader ;
  108.     TQ3InterpolationStyle    currentInterpolation;
  109.         
  110.     float            width;
  111.     float            height;
  112.  
  113.     TQ3Point3D        cameraLocation;
  114.     TQ3Point3D        pointOfInterest;
  115.     TQ3Vector3D        xVector;
  116.     TQ3Vector3D        yVector;        //up vector
  117.     TQ3Vector3D        zVector;
  118.     
  119.     // Delta Factors
  120.     float            xRotFactor;
  121.     float            yRotFactor;
  122.     float            zRotFactor;
  123.     float            xMoveFactor;
  124.     float            yMoveFactor;
  125.     float            zMoveFactor;
  126.     float            controlFactor;
  127.     
  128. } DocumentRecord, *DocumentPtr, **DocumentHandle ;
  129.  
  130.  
  131. //--------------------------------------------------------------------------------------------
  132. //  Function Prototypes (event handlers and functions)
  133. //
  134.  
  135. // apple event handlers
  136. pascal OSErr    MyAEHandleOAPP(AppleEvent *theAppleEvent,AppleEvent *reply,long refCon) ;
  137. pascal OSErr     MyAEHandleODOC(AppleEvent *theAppleEvent,AppleEvent *reply,long refCon) ;
  138. pascal OSErr     MyAEHandlePDOC(AppleEvent *theAppleEvent,AppleEvent *reply,long refCon) ;
  139. pascal OSErr     MyAEHandleQUIT(AppleEvent *theAppleEvent,AppleEvent *reply,long refCon) ;
  140. pascal OSErr     MyAEHandleDragRecv(AppleEvent *theAppleEvent,AppleEvent *reply,long refCon) ;
  141.  
  142. // function prototypes
  143. void             MyInitDeltaFactors(DocumentPtr mydocument);
  144. void             MyDoMouseMove(WindowPtr theWindow, EventRecord *theEvent);
  145. void             MyDoKeyMove(WindowPtr theWindow, EventRecord *theEvent, char theKey);
  146. Boolean         CheckKey(short keyCode);
  147.  
  148.